package com.friend.chat.db.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import com.friend.chat.db.entity.MessageEntity

/**
 * @des
 * @author batie fancy
 * @date 2023/1/7
 */
@Dao
interface  MessageDao {
    @Insert
    fun insertMessage(messageEntity: MessageEntity)

    @Query("SELECT * FROM table_message WHERE roomId =:cid ORDER BY dateTime DESC limit 1 ")
    fun queryTopMessage(cid: String):MutableList<MessageEntity>

    //分页查询 offset代表从第几条记录“之后“开始查询，limit表明查询多少条结果
    @Query("SELECT * FROM table_message WHERE roomId = :cid ORDER BY dateTime DESC limit 20 offset :offset")
    fun queryMessage(cid:String,offset:Int):MutableList<MessageEntity>

    //分页查询 offset代表从第几条记录“之后“开始查询，limit表明查询多少条结果
    @Query("SELECT * FROM table_message limit :limit offset :offset")
    fun queryMessage2(limit:Int,offset:Int):MutableList<MessageEntity>
}